import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/utils.dart';
import 'package:online_study/bean/recommend.dart';
import 'package:online_study/course/course_detail.dart';
import 'package:online_study/home/recommend_item.dart';
import 'package:online_study/theme/size.dart';

//首页好课推荐
class HomeRecommend extends StatefulWidget {
  @override
  _HomeRecommendState createState() => _HomeRecommendState();
}

class _HomeRecommendState extends State<HomeRecommend> {
  List<Recommend> recommends = [];

  @override
  void initState() {
    super.initState();
    recommends.add(Recommend(title: "员工日常行为规范", des: "员工行为“十不准”"));
    recommends.add(Recommend(title: "温故万邦文化", des: "董事长讲话精神学习"));
    recommends.add(Recommend(title: "把握职场新动力", des: "步入职场的你必不可少"));
    recommends.add(Recommend(title: "PS入门基础课", des: "P图不找人-入门课程"));
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: ThemeSize.width9),
      child:GridView.builder(
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 2,
            crossAxisSpacing: ThemeSize.width9,
            mainAxisSpacing: ThemeSize.height6),
        itemBuilder: (BuildContext context, int index) {
          return GestureDetector(
            child: RecommendItem(recommends[index]),
            onTap: () {
              Get.to(() => CourseDetailPage());
            },
          );
        },
        itemCount: recommends.length,
        physics: NeverScrollableScrollPhysics(),
        shrinkWrap: true,
      ),
    );
  }
}
